import os
import re

__author__="simon"
__date__ ="$Mar 17, 2011 9:24:53 PM$"


def main():
    xmlfiles = [] # [(file,[strings])]

    for file in find_files():
        xmlfiles.append((file,get_strings(file)))

    for xmlfile in xmlfiles:
        missingvalues=[]

        for entry in xmlfiles:
            missingvalues.extend(diff(xmlfile[1],entry[1]))

        print xmlfile[0],"is missing: \n"
        for value in missingvalues:
            print "        "+value
        print "\n\n\n"



# -> [(lang,file)]
def find_files():
    files=[]
    filename = "strings.xml"
    resdir = os.path.join("..","res")

    pattern = re.compile("values.*")

    for dir in os.listdir(resdir):
        if re.match(pattern,dir):
            files.append(os.path.join(resdir,dir, filename))

    return files


# file -> [string_names]
def get_strings(file):

    strings=[]

    pattern = re.compile("<string name=\"(\w+)\".*")

    f = open(file)

    for line in f:
        line = line.strip()
        m = re.match(pattern,line)
        if m is not None:
            strings.append(m.group(1))

    return strings

# those in B that are not in A
# [a...], [b...] -> [b | b not in A]
def diff(a,b):
    A = set(a)
    B = set(b)

    C = B-A

    return list(C)


if __name__ == "__main__":
    main()